package com.ly.lw.styledo.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.lidroid.xutils.BitmapUtils;
import com.ly.lw.styledo.R;
import com.ly.lw.styledo.auto.RecyclingPagerAdapter;
import com.ly.lw.styledo.bean.PlanList;


import java.util.List;

/**
 * @说 明：
 * @项目名称：1506adv
 * @包 名： com.qianfeng.zhangwei.extras.meilishuo.adapter
 * @类 名： AutoImagePageAdapter
 * @创 建人： zhangwei
 * @创建时间：2015-07-08 14:35
 * @版 本：v1.0
 * @修 改人：
 * @修改时间：
 * @修改备注：
 */
public class AutoImagePageAdapter extends RecyclingPagerAdapter {
    private List<PlanList> imgUrls;
    private Context context;
    private LayoutInflater inflater;
    private BitmapUtils bitmapUtils;


    public AutoImagePageAdapter(List<PlanList> imgUrls, Context context, BitmapUtils bitmapUtils) {
        this.imgUrls = imgUrls;
        this.context = context;
        inflater = LayoutInflater.from(context);
        this.bitmapUtils = bitmapUtils;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup container) {
        ViewHolder vh;
        if (convertView == null) {
            convertView = inflater.inflate(R.layout.main_head_layout, container, false);
            vh = new ViewHolder(convertView);
            convertView.setTag(vh);
        } else {
            vh = (ViewHolder) convertView.getTag();

        }
        bitmapUtils.display(vh.img, imgUrls.get(getCurrentPosition(position)).getBanner_img());

        return convertView;
    }

    private int getCurrentPosition(int position) {
        return position % imgUrls.size();
    }

    private class ViewHolder {
        ImageView img;

        public ViewHolder(View itemView) {
            this.img = (ImageView) itemView.findViewById(R.id.item_head_img);
        }
    }


    @Override
    public int getCount() {
        return imgUrls != null && !imgUrls.isEmpty() ? Integer.MAX_VALUE : 0;
    }
}
